package com.bit.demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-04
 * Time: 11:47
 */
class Animal {
    //父类
    //基类
    //超类
    public String name;
    public int age;
    protected int count;

    public Animal(String name, int age){
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println("eat");
        System.out.println(count);
    }
}
//    is          a
class Dog extends Animal{//继承animal里边的东西
    //子类，派生类
    /*public Dog(){
        super();
    }*/
    public Dog(String name, int age){
        super(name, age);//显示调用构造方法且只能在这里边出现且在第一行
        //两个参数：调用父类两个参数的构造方法
    }
}
class Bird extends Animal{
    public String wing;
    public String name;//null

    public Bird(String name, int age, String wing){
        super(name, age);
        this.wing = wing;
    }

    public void fly(){
        System.out.println(super.name + "fly" + age);//继承name
    }
}
public class TestDemo {

    public static void main(String[] args) {
        /*Dog dog = new Dog("haha", 16);
        Animal animal = dog;*/
        Animal animal = new Dog("haha",19);//父类引用指向子类对象
    }

    public int val = 10;
    protected int val2 = 99;
    public static void main2(String[] args) {
        Bird bird = new Bird("heihei", 18, "飞翔");
        System.out.println(bird.name);
        //bird.eat();
        bird.fly();
        System.out.println(bird.count);
    }

    public static void main1(String[] args) {
        Dog dog = new Dog("haha", 16);
        dog.name = "haha";
        System.out.println(dog.name);
        dog.eat();

        Bird bird = new Bird("heihei", 18, "飞翔");
        bird.name = "heihei";
        System.out.println(bird.name);
        bird.eat();
        bird.fly();
    }
}
